//
//  CellOfHotCommunity.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/10.
//  Copyright © 2016年 KX. All rights reserved.
//
#import "FreeTravelMacro.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"
#import "CellOfHotCommunity.h"
@interface CellOfHotCommunity ()

@end
@implementation CellOfHotCommunity
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageViewOfAvatar = [[UIImageView alloc]init];
        self.imageViewOfFirstBigpic_arr = [[UIImageView alloc]init];
        self.imageViewOfSecondBigpic_arr = [[UIImageView alloc]init];
        self.imageViewOfThirdBigpic_arr = [[UIImageView alloc]init];
        self.labelOfReply_time = [[UILabel alloc]init];
        self.labelOfReply_num = [[UILabel alloc]init];
        self.labelOfAuthor = [[UILabel alloc]init];
        self.labelOfTitle = [[UILabel alloc]init];
        self.labelOfForum = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.imageViewOfAvatar];
        [self.contentView addSubview:self.imageViewOfFirstBigpic_arr];
        [self.contentView addSubview:self.imageViewOfSecondBigpic_arr];
        [self.contentView addSubview:self.imageViewOfThirdBigpic_arr];
        [self.contentView addSubview:self.labelOfForum];
        [self.contentView addSubview:self.labelOfTitle];
        [self.contentView addSubview:self.labelOfAuthor];
        [self.contentView addSubview:self.labelOfReply_num];
        [self.contentView addSubview:self.labelOfReply_time];
        
    }
    return self;
    
}



- (void)layoutSubviews{
    [super layoutSubviews];
    [self.imageViewOfAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).mas_offset(10);
        make.top.equalTo(self.contentView.mas_top).mas_offset(10);
        make.width.mas_offset(20);
        make.height.mas_offset(20);
    }];
    self.imageViewOfAvatar.layer.cornerRadius = 10;
    self.imageViewOfAvatar.layer.masksToBounds = YES;
    [self.labelOfAuthor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).mas_offset(10);
        make.left.equalTo(self.imageViewOfAvatar.mas_right).mas_offset(10);
        make.height.mas_offset(10);
    }];
    self.labelOfAuthor.textColor = [UIColor grayColor];
    self.labelOfAuthor.font = [UIFont systemFontOfSize:12];
    [self.labelOfTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageViewOfAvatar.mas_right).mas_offset(10);
        make.top.equalTo(self.labelOfAuthor.mas_bottom).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-20);
    }];
    self.labelOfTitle.font = [UIFont systemFontOfSize:15];
    self.labelOfTitle.numberOfLines = 0;
    
    self.labelOfForum.textColor = COLORFORFREETRAVEL;
            self.labelOfForum.font = [UIFont systemFontOfSize:12];
    self.labelOfReply_time.textColor = [UIColor grayColor];
    
    self.labelOfReply_num.textColor = [UIColor grayColor];
            self.labelOfReply_num.font = [UIFont systemFontOfSize:12];
            self.labelOfReply_time.font = [UIFont systemFontOfSize:12];

    
    
    
    
    if (self.model.bigpic_arr.count >= 1) {
        [self.imageViewOfFirstBigpic_arr mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.imageViewOfAvatar.mas_right).mas_offset(10);
            make.top.equalTo(self.labelOfTitle.mas_bottom).mas_offset(10);
            make.width.mas_offset((SCREEN_WIDTH-80)/3);
            make.height.equalTo(self.imageViewOfFirstBigpic_arr.mas_width);
            
        }];
        if (self.model.bigpic_arr.count >= 2) {
            [self.imageViewOfSecondBigpic_arr mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.imageViewOfFirstBigpic_arr.mas_right).mas_offset(10);
                make.top.equalTo(self.labelOfTitle.mas_bottom).mas_offset(10);
                make.width.equalTo(self.imageViewOfFirstBigpic_arr.mas_width);
                make.height.equalTo(self.imageViewOfFirstBigpic_arr.mas_height);
            }];
            if (self.model.bigpic_arr.count == 3) {
                [self.imageViewOfThirdBigpic_arr mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self.imageViewOfSecondBigpic_arr.mas_right).mas_offset(10);
                    make.top.equalTo(self.labelOfTitle.mas_bottom).mas_offset(10);
                    make.height.equalTo(self.imageViewOfFirstBigpic_arr.mas_height);
                    make.width.equalTo(self.imageViewOfFirstBigpic_arr.mas_width);
                }];
            }
        }
    }
    if (self.model.bigpic_arr.count == 0) {
        [self.labelOfForum mas_remakeConstraints:^(MASConstraintMaker *make) {
            
                make.top.equalTo(self.labelOfTitle.mas_bottom).mas_offset(20);
            
            make.left.equalTo(self.imageViewOfAvatar.mas_right).mas_offset(10);
            
        }];
        [self.labelOfReply_num mas_remakeConstraints:^(MASConstraintMaker *make) {
            
                make.top.equalTo(self.labelOfTitle.mas_bottom).mas_offset(20);
            
            make.right.equalTo(self.contentView.mas_right).mas_offset(-20);
        }];
        
        [self.labelOfReply_time mas_remakeConstraints:^(MASConstraintMaker *make) {
            
                make.top.equalTo(self.labelOfTitle.mas_bottom).mas_offset(20);
           
            make.right.equalTo(self.labelOfReply_num.mas_left).mas_offset(-20);
        }];
    }else{
        [self.labelOfForum mas_remakeConstraints:^(MASConstraintMaker *make) {
           
                make.top.equalTo(self.imageViewOfFirstBigpic_arr.mas_bottom).mas_offset(20);
            
            make.left.equalTo(self.imageViewOfAvatar.mas_right).mas_offset(10);
            
        }];
        [self.labelOfReply_num mas_remakeConstraints:^(MASConstraintMaker *make) {
           
                make.top.equalTo(self.imageViewOfFirstBigpic_arr.mas_bottom).mas_offset(20);
            
            make.right.equalTo(self.contentView.mas_right).mas_offset(-20);
        }];
        
        [self.labelOfReply_time mas_remakeConstraints:^(MASConstraintMaker *make) {
                            make.top.equalTo(self.imageViewOfFirstBigpic_arr.mas_bottom).mas_offset(20);
            
            make.right.equalTo(self.labelOfReply_num.mas_left).mas_offset(-20);
        }];
    }
    
    

    
}
- (void)setModel:(ModelOfHotCommunityData *)model{
    _model = model;
    

    
    
    
    
   
    
    if (self.model.bigpic_arr.count >= 1) {
        
        
        self.imageViewOfFirstBigpic_arr.hidden = NO;
        
        [self.imageViewOfFirstBigpic_arr sd_setImageWithURL:[NSURL URLWithString:model.bigpic_arr[0]]];
        if (self.model.bigpic_arr.count >= 2) {
            [self.imageViewOfSecondBigpic_arr sd_setImageWithURL:[NSURL URLWithString:model.bigpic_arr[1]]];
            self.imageViewOfSecondBigpic_arr.hidden = NO;
            
            
            if (self.model.bigpic_arr.count == 3) {
                 [self.imageViewOfThirdBigpic_arr sd_setImageWithURL:[NSURL URLWithString:model.bigpic_arr[2]]];
                
                
                self.imageViewOfThirdBigpic_arr.hidden = NO;
            }        }else{
            self.imageViewOfThirdBigpic_arr.hidden = YES;
        }
    } else {
        
        self.imageViewOfSecondBigpic_arr.hidden = YES;
        self.imageViewOfFirstBigpic_arr.hidden = YES;
        self.imageViewOfThirdBigpic_arr.hidden = YES;
    }
    
    [self.imageViewOfAvatar sd_setImageWithURL:[NSURL URLWithString:model.avatar]];
    self.labelOfForum.text= model.forum;
    self.labelOfTitle.text = model.title;
    self.labelOfAuthor.text = model.author;
    self.labelOfReply_num.text = [NSString stringWithFormat:@"%ld",model.reply_num];
    self.labelOfReply_time.text = model.reply_time;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
